<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page  import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>
<%@ page import = "java.util.Date" %>
<%@ page import = "java.text.SimpleDateFormat" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Edit Personal</title>
<link rel="stylesheet" type="text/css" href="css/stylev2.css" />
<link rel="stylesheet" type="text/css" href="css/student-system.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script src="js/jquery.ajaxfileupload.js"></script>

<style type="text/css">
	a {
      text-decoration:none;
   }
</style>
<script>

	$(document).ready(function() {
		var patt = new RegExp("[#$%^*?!~`<>]");
		var src_path_full="null";
		
		$('input[type="file"]').ajaxfileupload({
			'action' : 'UploadServletStudentAddNormal',
			'onComplete' : function(response) {
				$('#upload').hide();
				$('#message').show();
				
				var statusVal = JSON.stringify(response.status);
					alert("statusVal:"+statusVal);
	
				if(statusVal == "false")
				{
					$("#message").html("<font color='red'>"+ JSON.stringify(response.message) +" </font>");
					
				}	
				if(statusVal == "true")
				{
					
					 var xmlhttp;
						
						if(window.XMLHttpRequest) {
							// code for IE7+, Firefox, Chrome, Opera, Safari
							xmlhttp = new XMLHttpRequest();
						}
						else {
							// code for IE6, IE5
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
						}
						
						xmlhttp.onreadystatechange = function() {
							if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {	
								
								//alert("Back from student_edit_personal_get_photo_temp:");
								
					
							
							
									
							src_path_full = xmlhttp.responseText;
						//	alert("src_path_full:"+src_path_full);
							var src_path_temp = src_path_full.split("/");
							var length = src_path_temp.length;
							
							var src_path_a = src_path_temp[length-2];
							var src_path_b = src_path_temp[length-1];
							
							var src_path = src_path_a+"/"+src_path_b;
						

							
							
							$("#student_image").attr('src',src_path);
							$("#message").html("<font color='green'>"+ JSON.stringify(response.message) +" </font>");		
									
							// end if check state
							}// end function
						
						}						
						xmlhttp.open("POST", "student_edit_personal_get_photo_temp.jsp", true);
						xmlhttp.send();
		
				}			
			},
			'onStart' : function() {
				$('#upload').show();
				$('#message').hide();
			}
		});
		
		$('#save').click(function(){
			
			 var check = "";
			 var error = "กรุณากรอก";
			//////////////////////////////////////////////////////////////
			 var personal_id = document.getElementById('personalId');
		 	 personal_id_value = personal_id.value;
		 	 
		   	 if(patt.test(personal_id_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			 }
		 	

		 	
			 //////////////////////////////////////////////////////////////
		     var title = document.getElementsByName('title');
			 var title_value;
			  if(patt.test(title_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			 
			 for(var i = 0; i < title.length; i++){
			    if(title[i].checked){
			        title_value = title[i].value;
			    }
			 }
			    
				if(title_value==null)
				{
					error = error + " คำนำหน้า";
					check="X";
				
				}
				else if (title_value=="etc")
				{
					title_value =  $('#title_etc').val();
					alert(title_value);/////////////try//////////////////////////////////
						if(title_value==null){
							
								error = error + " คำนำหน้าแบบกำหนดเอง";
								check="X";
							
						} 
						
				}
				//////////////////////////////////////////////////////////////
				 
				var name_th = document.getElementById('name');
				var name_th_value = name_th.value;
				if(name_th_value=="")
				{
					error = error + " ชื่อภาษาไทย";	
					check="X";
				}
				if(patt.test(name_th_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				//////////////////////////////////////////////////////////////
				 
				var surname_th = document.getElementById('surname');
				var surname_th_value = surname_th.value;
				if(surname_th_value=="")
				{
					error = error + " นามสกุลภาษาไทย";	
					check="X";
				}
				if(patt.test(surname_th_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				 //////////////////////////////////////////////////////////////
				var gender = document.getElementsByName('gender');
				var gender_value;
				
				 for(var j = 0; j < gender.length; j++){
					    if(gender[j].checked){
					        gender_value = gender[j].value;
					    }
					 }
			
				 if(gender_value==null)
				 {
					 error = error + " เพศ";
					 check="X";
				 }
				
					//////////////////////////////////////////////////////////////
				 
					var student_id = document.getElementById('studentId');
					var student_id_value = student_id.value;
					if(student_id_value=="")
					{
						error = error + " รหัสนักศึกษา";	
						check="X";
					}
				 //////////////////////////////////////////////////////////////

				 var date_of_birth = document.getElementById('date_of_birth');
				 var date_of_birth_value = date_of_birth.value; 
				 
				 if(date_of_birth_value=="")
				 {
					 error = error + " วันเกิด";
					 check="X";
				 }
				 //////////////////////////////////////////////////////////////
				 var select_entrance = document.getElementById('entrance');		
				 var entrance_value = select_entrance.options[select_entrance.selectedIndex].value;	 
			
				if(entrance_value=="select")
				{
					error = error + " รูปแบบการเข้าศึกษา";	
					check="X";
					
				}
				 //////////////////////////////////////////////////////////////
				 var select_degree = document.getElementById('degree');
				 
				 var degree_value = select_degree.options[select_degree.selectedIndex].value;	 
				
				 if(degree_value=="select")
				 {
					 error = error + " ระดับการศึกษา";
					 check="X";
				 }
				 //////////////////////////////////////////////////////////////
				 var select_degree = document.getElementById('degree');		
				 var degree_value = select_degree.options[select_degree.selectedIndex].value;	 
			
				if(degree_value=="select")
				{
					error = error + " สถานะ";	
					check="X";
					
				}
				/////////////////////////////////////////////////////////
				 var start_date = document.getElementById('start_date');
				 var start_date_value = start_date.value; 
				 
				 if(start_date_value=="")
				 {
					 error = error + " วันที่เริ่มเข้าศึกษา";
					 check="X";
				 }
				 //////////////////////////////////////////////////////////////
				 var select_status = document.getElementById('status');		
				 var status_value = select_status.options[select_status.selectedIndex].value;	 
			
				if(status_value=="select")
				{
					error = error + " สถานะนักศึกษา";	
					check="X";
					
				}
				
				if(error != "กรุณากรอก"){
					alert(error);
				}
				
				////////////////////get data ///////////////////
				
				
				var name_en = document.getElementById('name_en');
				var name_en_value = name_en.value;
				if(patt.test(name_en_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			
				var surname_en = document.getElementById('surname_en');
				var surname_en_value = surname_en.value;
				if(patt.test(surname_en_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				
			     var marital_status = document.getElementsByName('marital_status');
				 var marital_status_value;
				 
		
				 
				 for(var i = 0; i < marital_status.length; i++){
				    if(marital_status[i].checked){
				        marital_status_value = marital_status[i].value;
				    }
				 }
				 
				 
				var address = document.getElementById('address');
				
				var address_value = address.value;
					
				if(patt.test(address_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			
				
				var tel = document.getElementById('phonenumber');
				var tel_value = tel.value;
				
				if(patt.test(tel_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				var patt_email = new RegExp("[#$%^*?!~`<>]");
				var email = document.getElementById('email');
				var email_value = email.value;
				
				if(patt_email.test(email_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				var facebook = document.getElementById('facebook');
				var facebook_value = facebook.value;
				
				if(patt.test(facebook_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
			
				var picture_value = src_path_full;
				alert("picture_value:"+picture_value);
				
				var father_name = document.getElementById('fatherName');
				var father_name_value = father_name.value;
				
				if(patt.test(father_name_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				var father_address = document.getElementById('fatherAddress');
				var father_address_value = father_address.value;
				
				if(patt.test(father_address_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			
				
				var father_tel = document.getElementById('fatherPhone');
				var father_tel_value = father_tel.value;
				
				if(patt.test(father_tel_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			
				var mother_name = document.getElementById('motherName');
				var mother_name_value = mother_name.value;
				
				if(patt.test(mother_name_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				var mother_address = document.getElementById('motherAddress');
				var mother_address_value = mother_address.value;
				
				if(patt.test(mother_address_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
			
				
				var mother_tel = document.getElementById('motherPhone');
				var mother_tel_value = mother_tel.value;
				
				if(patt.test(mother_tel_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				
				var parent_name_value;
				var parent_address_value;
				var parent_tel_value;
				
			    var parent_choose = document.getElementsByName('parent_name');
			    var parent_choose_value;
			    
				 for(var i = 0; i < parent_choose.length; i++){
				    if(parent_choose[i].checked){
				        parent_choose_value = parent_choose[i].value;
				    }
				 }
				 
				if(parent_choose_value=="sameFather")
				{
					parent_name_value = father_name_value;
					parent_address_value = parent_address_value;
					parent_tel_value = parent_tel_value;			
				
				}
				else if(parent_choose_value=="sameMother"){
					parent_name_value = mother_name_value;
					parent_address_value = mother_address_value;
					parent_tel_value = mother_tel_value;
				
				}
				else if(parent_choose_value=="etc")
				{
					var parent_name = document.getElementById('parentName');
					var parent_address =document.getElementById('parentAddress');
					var parent_tel = document.getElementById('parentPhone');
						parent_name_value = parent_name.value;
						parent_address_value  = parent_address.value;
						parent_tel_value = parent_tel.value;
						if(patt.test(parent_name_value)||patt.test(parent_address_value)||patt.test(parent_tel_value)) { 
							
							check="X";
							error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
						}
					
				}
							
		
				
				var school = document.getElementById('school');
				var school_value = school.value;
				
				
				if(patt.test(school_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				var gpa = document.getElementById('gpa');
				var gpa_value = gpa.value;
				
				
				if(patt.test(gpa_value)) { 
					
					check="X";
					error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
				}
				
				
				
				var lecturer = document.getElementById("lecturer_name").value;			
				var lecturer_name_value =  lecturer.substr(0,lecturer.indexOf(' '));	
				var lecturer_surname_value = lecturer.substr(lecturer.indexOf(' ')+1).trim();		
		/*		
				var curriculum_id = "<%=request.getParameter("curriculum")%>";
				var department_id = "<%=request.getParameter("department")%>";
		*/		
		
				var curriculum_id = document.getElementById("curriculum").value;
				var department_id = document.getElementById("department").value;
			
				var full_name_id = document.getElementById("full_name_id").value;
				var index = document.getElementById("index").value;
		/*		
				alert(curriculum_id);
				alert(department_id);
				alert(full_name_id);
				alert(index);
		*/
	/*						
				//final Checking
				alert("personal_id:"+personal_id_value);
				alert("title:"+title_value);
				alert("name_th:"+name_th_value);
				alert("surname_th:"+surname_th_value);
				alert("name_en:"+name_en_value);
				alert("surname_en:"+surname_en_value);
				alert("gender:"+gender_value);
				alert("marital_status:"+marital_status_value);
				alert("date_of_birth:"+date_of_birth_value); // 
				alert("address:"+address_value);
				alert("tel:"+tel_value);
				alert("email:"+email_value);
				alert("facebook:"+facebook_value);
				alert("picture:"+picture_value);
				alert("father_name:"+father_name_value);
				alert("father_address:"+father_address_value)
				alert("father_tel:"+father_tel_value);
				alert("mother_name:"+mother_name_value);
				alert("mother_address:"+mother_address_value);
				alert("mother_tel:"+mother_tel_value);
				alert("parent_name:"+parent_name_value);
				alert("parent_address:"+parent_address_value);
				alert("parent_tel:"+parent_tel_value); 
				alert("student_id:"+student_id_value);
				alert("entrance_id:"+entrance_value);
				alert("school:"+school_value);
				alert("gpa:"+gpa_value);
				alert("start_date:"+start_date_value);
				alert("status:"+status_value)
				alert("lecturer_name:"+lecturer_name_value);
				alert("lecturer_surname:"+lecturer_surname_value);
				alert("curriculum_id:"+curriculum_id);
	*/		
				
				
				if(check=="")
				{
					/* AJAX */
					var xmlhttp;
					
					if(window.XMLHttpRequest) {
						// code for IE7+, Firefox, Chrome, Opera, Safari
						xmlhttp = new XMLHttpRequest();
					}
					else {
						// code for IE6, IE5
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					}
					
					xmlhttp.onreadystatechange = function() {
						if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {									
						
							alert("I'm back");
							var result = xmlhttp.responseText.trim();
							alert("result:"+result);
							if(result=="success"){
								alert("บันทึกข้อมูลสำเร็จ");
								window.location="student_edit.jsp";
								// redirect
								
								
							}
							else if(result=="full_name"){
								alert("มีข้อผิดพลาดเกี่ยวกับข้อมูลชื่อของนักศึกษา กรุณาตรวจสอบอีกครั้ง");
								
							}
							else if(result=="people"){
								alert("มีข้อผิดพลาดเกี่ยวกับข้อมูลส่วนตัวของนักศึกษา กรุณาตรวจสอบอีกครั้ง");
								
							}
							else if(result=="student"){
								alert("มีข้อผิดพลาดเกี่ยวกับข้อมูลทั่วไปของนักศึกษา กรุณาตรวจสอบอีกครั้ง");
								
							}
							else{
								alert("บันทึกข้อมูลไม่สำเร็จ Error code:100");
								
							}
							
							//document.location.href = "admin_account.jsp";
						}
					}
					
					
					var parameter = "personal_id="+personal_id_value+
								    "&title_th="+title_value+
								    "&name_th="+name_th_value+
								    "&surname_th="+surname_th_value+
								    "&name_en="+name_en_value+
									"&surname_en="+surname_en_value+
									"&gender="+gender_value+
									"&marital_status="+marital_status_value+
									"&date_of_birth="+date_of_birth_value+
									"&address="+address_value+
									"&tel="+tel_value+
									"&email="+email_value+
									"&facebook="+facebook_value+
									"&picture="+picture_value+
									"&father_name="+father_name_value+
									"&father_address="+father_address_value+
									"&father_tel="+father_tel_value+
									"&mother_name="+mother_name_value+
									"&mother_address="+mother_address_value+
									"&mother_address="+mother_address_value+
									"&parent_name="+parent_name_value+
									"&parent_address="+parent_address_value+
									"&parent_tel="+parent_tel_value+
									"&student_id="+student_id_value+
									"&entrance_id="+entrance_value+
									"&school="+school_value+
									"&gpa="+gpa_value+
									"&start_date="+start_date_value+
									"&status_id="+status_value+
									"&lecturer_name="+lecturer_name_value+
									"&lecturer_surname="+lecturer_surname_value+
									"&curriculum_id="+curriculum_id+
									"&department_id="+department_id+
									"&full_name_id="+full_name_id+
									"&picture="+picture_value+
									"&index="+index;
										
					alert("parameter : "+parameter);
					
					xmlhttp.open("POST", "student_edit_personal_save.jsp?"+parameter, true);
					xmlhttp.send();
				}
				else{
					
						alert("กรุณาตรวจสอบความถูกต้องอีกครั้ง");
				}
					 
			
		});
		
	});

	function parent_etc(){
		
		var parent_name_box = document.getElementById("parentName");
		var parent_address_box = document.getElementById("parentAddress");
		var parent_tel_box = document.getElementById("parentPhone");
		
		parent_name_box.readOnly = false;
		parent_address_box.readOnly = false;
		parent_tel_box.readOnly = false;
	
	}
	function parent_is_father(){
		
		var parent_name_box = document.getElementById("parentName");
		var parent_address_box = document.getElementById("parentAddress");
		var parent_tel_box = document.getElementById("parentPhone");
		
		parent_name_box.readOnly = true;
		parent_address_box.readOnly = true;
		parent_tel_box.readOnly = true;
	
	}
	function parent_is_mother(){
		
		var parent_name_box = document.getElementById("parentName");
		var parent_address_box = document.getElementById("parentAddress");
		var parent_tel_box = document.getElementById("parentPhone");
		
		parent_name_box.readOnly = true;
		parent_address_box.readOnly = true;
		parent_tel_box.readOnly = true;
	
	}
	
	function search_name(name) {	
		if($('#namelist').find('option').length > 0) {
			
			$('#namelist').find('option').remove();
		}
		if(name != "") {
			/* AJAX */
			var xmlhttp;
			
			if(window.XMLHttpRequest) {
				// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			}
			else {
				// code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					
					
					var jsonObj = JSON.parse(xmlhttp.responseText);
					
					if(jsonObj.length == 0) {
						// no data
					}
					else{
						for(i in jsonObj) {
							var text = jsonObj[i].nameTH+" "+jsonObj[i].surnameTH;
							var option = '<option value="'+text+'" >';
							
							$('#namelist').append(option);
						}
					}
				}
			}
			
			xmlhttp.open("POST", "search_name_lecturer.jsp?name="+name, true);
			xmlhttp.send();
		}			
	}

	// check title etc was click
	function click_title_etc() {
		document.getElementById('title_etc').readOnly = false;
		$('#title_etc').focus();
	}
	
	function click_title() {
		document.getElementById('title_etc').readOnly = true;
	}
</script>


</head>
<body>

<%	
//get session
	String strUser = String.valueOf(session.getAttribute("sUser"));
	HttpSession htp_session = request.getSession();
	

	// check session
	if (htp_session == null || htp_session.getAttribute("sUser") == null) {
	    // Forward the control to login.jsp if authentication fails or session expires
	    request.getRequestDispatcher("/login.jsp").forward(request,
	        response);
	}
/*	
	if("admin".equals(htp_session.getAttribute("sUser"))){%>
	<script>alert("This user dont have PERMISSION to access this zone.");</script>
	<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
	<%}
	
	String department_id = request.getParameter("department");
	String curriculum_id = request.getParameter("curriculum");
	
	
	System.out.println("Select Curriculum :"+curriculum_id);
	System.out.println("Select Depart:"+department_id);
*/	
	String student_id = request.getParameter("student_id");
	System.out.println("@ student_edit_personal student_id:"+student_id);
	
	
	if(student_id==null)
	{	
		System.out.println("Redirect");
		response.sendRedirect("student_edit.jsp");	
	}
	
	
//////////get permission ///////////
	
	String name = String.valueOf(session.getAttribute("name"));
	String surname = String.valueOf(session.getAttribute("surname"));
	String role_name = String.valueOf(session.getAttribute("student_role"));
	
	String department_id2 = String.valueOf(session.getAttribute("department_id"));
	
	System.out.println("name : " + name);///////////////////////////////
	System.out.println("department_id : " + department_id2);/////////////////////////
	
	
	List<String> system_name = new ArrayList<String>();
	
	Permission permission = new Permission(strUser,name);
	permission.setDepartmentId(department_id2);
	permission.setStudentCreate(Boolean.valueOf(String.valueOf(session.getAttribute("student_create"))));
	permission.setStudentDelete(Boolean.valueOf(String.valueOf(session.getAttribute("student_delete"))));
	permission.setStudentRead(Boolean.valueOf(String.valueOf(session.getAttribute("student_read"))));
	permission.setStudentUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("student_update"))));
	
	String permiss = "";
	if(permission.getStudentCreate()) {
		permiss = permiss + "Add";
	}
	if(permission.getStudentUpdate()) {
		if("".equals(permiss)) {
			permiss = permiss + "Edit";
		} else {
			permiss = permiss + " Edit";
		}
	}
	if(permission.getStudentRead()) {
		if("".equals(permiss)) {
			permiss = permiss + "Read";
		} else {
			permiss = permiss + " Read";
		}
	}
	if(permission.getStudentDelete()) {
		if("".equals(permiss)) {
			permiss = permiss + "Delete";
		} else {
			permiss = permiss + " Delete";
		}
	}
	//check permission
	if(!permission.getStudentUpdate()){%>
		<script>alert("This user dont have PERMISSION to access this zone.");</script>
		<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=student_home.jsp"> 	
	<%}
	
	//set Database Connection
	String hostProps = "";
	String usernameProps  = "";
	String passwordProps  = "";
	
	try {
		//get current path
		ServletContext servletContext = request.getSession().getServletContext();
		
		InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
		Properties props = new Properties();
		
		props.load(input);

		hostProps  = props.getProperty("host");
		usernameProps  = props.getProperty("username");
		passwordProps  = props.getProperty("password");
	} catch (Exception e) { 
		out.println(e);  
	}
	
	
	System.out.println("hostProperties : "+hostProps);////////////////try/////////////////
	System.out.println("usernameProperties : "+usernameProps);////////////////try/////////////////
	System.out.println("passwordProperties : "+passwordProps);////////////////try/////////////////
	
	// connect database
	Connection connect = null;		
	try {
		Class.forName("com.mysql.jdbc.Driver");
	
		connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/AIMS" +
				"?user=" + usernameProps  + "&password=" + passwordProps + "&characterEncoding=tis620" );
	
		if(connect != null){
			System.out.println("Database Connect Sucesses.");
		} else {
			System.out.println("Database Connect Failed.");	
		}

	} catch (Exception e) {
		out.println(e.getMessage());
		e.printStackTrace();
	}
	
	System.out.println("@admin_student_edit_personal");
	
	
	Date date = new Date();
	int temp_year = date.getYear()+1900;
	int temp_month = date.getMonth()+1;
	int entrance_id = 0;
	int status_id = 0;
	String curr_id="";
	String lecturer_id="";
	String degree = null;
	Student stu = new Student();
	
	String father = "";
	String mother = "";
	String parent = "";
	String start_date_old = "";
	String full_name_id = "";
	String index = "";
	String title_th = "";
	String title_en = "";
	
	String department_id = "";
	String curriculum_id = "";
	
	List<Status> status = new ArrayList<Status>();
	List<Entrance> entrance = new ArrayList<Entrance>();
	try{
		
		ResultSet rs_status = connect.createStatement().executeQuery("SELECT status_id, status_name " 
				+ " FROM status " + " ORDER BY status_id");
		
		while(rs_status.next()) {
			Status sta = new Status();
			
			
			sta.setStatusId(Integer.parseInt(rs_status.getString("status_id")));
			sta.setStatusName(rs_status.getString("status_name"));
			
			status.add(sta);
		}
		
		ResultSet rs_entrance = connect.createStatement().executeQuery("SELECT entrance_id, entrance_name " 
				+ " FROM entrance " + " ORDER BY entrance_id");
		
		while(rs_entrance.next()) {
			Entrance ent = new Entrance();
			
			
			ent.setEntranceId(Integer.parseInt(rs_entrance.getString("entrance_id")));
			ent.setEntranceName(rs_entrance.getString("entrance_name"));
			
			entrance.add(ent);
		}
		
		
		
		ResultSet rs = 
				connect.createStatement().executeQuery(" SELECT S.picture, N.title_en, N.title_th, "+
						" N.name_th, N.surname_th , N.name_en , N.surname_en ,P.personal_id, P.gender,P.marital_status ,"+
					    " P.address , P.phone_number, P.email , P.facebook , S.father_name , S.father_address ,"+
						" S.father_phone ,S.mother_name , S.mother_address , S.mother_phone , S.parent_name,"+
					    " S.parent_address ,S.parent_phone ,S.student_id, S.start_date , S.entrance_id  , S.school ,"+
						" S.gpa , ST.status_name, ST.status_id ,D.department_name_th, S.curriculum_id ,P.date_of_birth ,S.lecturer_id "+
					    " , E.entrance_name, C.degree, S.start_date, N.full_name_id, P.index "+
					    " FROM student S, full_name N, department D, status ST, people P, entrance E, curriculum C "+
					    " WHERE S.index = P.index AND P.full_name_id = N.full_name_id "+
					    " AND S.department_id = D.department_id AND S.status_id = ST.status_id AND S.entrance_id=E.entrance_id "+
					    " AND S.curriculum_id=C.curriculum_id AND S.student_id='"+student_id+"'");
		

		
		
		while(rs.next())
		{
			
			
			String src_path_full = rs.getString("picture");
			System.out.println("src_path_full:"+src_path_full);
		//	System.out.println(src_path_full.equals("null"));
		//	System.out.println(!("null").equals(src_path_full));
		//	System.out.print((src_path_full!=null)||(!("null").equals(src_path_full)));
			
			if((src_path_full!=null)&&(!("null").equals(src_path_full)))
			{
				String[] src_path_temp = src_path_full.split("/");	
				int length = src_path_temp.length;
				
				String src_path_a = src_path_temp[length-2];
				String src_path_b = src_path_temp[length-1];
				
				String src_path = src_path_a+"/"+src_path_b;
				
				stu.setPicture(src_path);
			
			}else{
				stu.setPicture("upload/default_person_icon.jpg");
				
			}
			
			
			
			if(rs.getString("personal_id")==null || "null".equals(rs.getString("personal_id")))
			{
				stu.setPersonalId("");
			}	
			else{
				stu.setPersonalId(rs.getString("personal_id"));
			}
			//stu.setPersonalId(rs.getString("personal_id"));
			
			if(rs.getString("title_th")==null || "null".equals(rs.getString("title_th")))
			{
				stu.setTitle("");	
			}else{
				stu.setTitle(rs.getString("title_th"));
			}
			
			if(rs.getString("title_en")==null || "null".equals(rs.getString("title_en")))
			{
				stu.setTitleEN("");	
			}else{
				stu.setTitleEN(rs.getString("title_en"));
			}
			//stu.setTitle(rs.getString("title_th"));
			//stu.setTitleEN(rs.getString("title_en"));
			
			
			stu.setNameTH(rs.getString("name_th"));
			stu.setSurnameTH(rs.getString("surname_th"));
			
			if(rs.getString("name_en")==null || "null".equals(rs.getString("name_en")))
			{
				stu.setNameEN("");
			}else{
				stu.setNameEN(rs.getString("name_en"));
			}
			if(rs.getString("surname_en")==null || "null".equals(rs.getString("surname_en")))
			{
				stu.setSurnameEN("");
			}else{
				stu.setSurnameEN(rs.getString("surname_en"));
			}
			//stu.setNameEN(rs.getString("name_en"));
			//stu.setSurnameEN(rs.getString("surname_en"));
			
			
			if(rs.getString("date_of_birth")==null || "null".equals(rs.getString("date_of_birth")))
			{
				stu.setBirtgdate("");
			}else{
				stu.setBirtgdate(rs.getString("date_of_birth"));				
			}
			//stu.setBirtgdate(rs.getString("date_of_birth"));
			
			stu.setGender(rs.getString("gender"));

			if(rs.getString("marital_status")==null || "null".equals(rs.getString("marital_status")))
			{
				stu.setMaritalStatus("");
				
			}else{
				stu.setMaritalStatus(rs.getString("marital_status"));
			}
			//stu.setMaritalStatus(rs.getString("marital_status"));
			
			if(rs.getString("address")==null || "null".equals(rs.getString("address")))
			{
				stu.setAddress("");
			}else{
				stu.setAddress(rs.getString("address"));
			}
			//stu.setAddress(rs.getString("address"));
			
			if(rs.getString("phone_number")==null || "null".equals(rs.getString("phone_number")))
			{
				stu.setTelephone("");
			}else{
				stu.setTelephone(rs.getString("phone_number"));
			}
			//stu.setTelephone(rs.getString("phone_number"));
			
			if(rs.getString("email")==null || "null".equals(rs.getString("email")))
			{
				stu.setEmail("");
			}else{
				stu.setEmail(rs.getString("email"));
			}
			//stu.setEmail(rs.getString("email"));
			
			if(rs.getString("facebook")==null || "null".equals(rs.getString("facebook")))
			{
				stu.setFacebook("");
			}else{
				stu.setFacebook(rs.getString("facebook"));
			}
			//stu.setFacebook(rs.getString("facebook"));
			
			if(rs.getString("father_name")==null || "null".equals(rs.getString("father_name")))
			{
				stu.setFatherName("");
			}else{
				stu.setFatherName(rs.getString("father_name"));
			}
			//stu.setFatherName(rs.getString("father_name"));	
			
			if(rs.getString("father_address")==null || "null".equals(rs.getString("father_address")))
			{
				stu.setFatherAddress("");
			}else{
				stu.setFatherAddress(rs.getString("father_address"));
			}
			//stu.setFatherAddress(rs.getString("father_address"));
			
			if(rs.getString("father_phone")==null || "null".equals(rs.getString("father_phone")))
			{
				stu.setFatherTelephone("");
			}else{
				stu.setFatherTelephone(rs.getString("father_phone"));
			}
			//stu.setFatherTelephone(rs.getString("father_phone"));
			
			if(rs.getString("mother_name")==null || "null".equals(rs.getString("mother_name")))
			{
				stu.setMotherName("");
			}else{
				stu.setMotherName(rs.getString("mother_name"));
			}
			//stu.setMotherName(rs.getString("mother_name"));	
			
			if(rs.getString("mother_address")==null || "null".equals(rs.getString("mother_address")))
			{
				stu.setMotherAddress("");
			}else{
				stu.setMotherAddress(rs.getString("mother_address"));
			}
			//stu.setMotherAddress(rs.getString("mother_address"));
			
			if(rs.getString("mother_phone")==null || "null".equals(rs.getString("mother_phone")))
			{
				stu.setMotherTelephone("");
			}else{
				stu.setMotherTelephone(rs.getString("mother_phone"));
			}
			//stu.setMotherTelephone(rs.getString("mother_phone"));
			
			if(rs.getString("parent_name")==null || "null".equals(rs.getString("parent_name")))
			{
				stu.setParentName("");
			}else{
				stu.setParentName(rs.getString("parent_name"));
			}
			//stu.setParentName(rs.getString("parent_name"));		
			
			if(rs.getString("parent_address")==null || "null".equals(rs.getString("parent_address")))
			{
				stu.setParentAddress("");
			}else{
				stu.setParentAddress(rs.getString("parent_address"));
			}
			//stu.setParentAddress(rs.getString("parent_address"));
			
			if(rs.getString("parent_phone")==null || "null".equals(rs.getString("parent_phone")))
			{
				stu.setParentTelephone("");
			}else{
				stu.setParentTelephone(rs.getString("parent_phone"));
			}
			//stu.setParentTelephone(rs.getString("parent_phone"));
			
			
			stu.setStudentId(rs.getString("student_id"));
		
			start_date_old = rs.getString("start_date");
			full_name_id = rs.getString("full_name_id");
			index = rs.getString("index");
			
   			father = rs.getString("father_name");				
   			mother = rs.getString("mother_name");				
   			parent = rs.getString("parent_name");
   			
   			title_th = rs.getString("title_th");	
   			title_en = rs.getString("title_en");	
			
   			
			Date start_date = new SimpleDateFormat("yyyy-MM-dd",java.util.Locale.US).parse(rs.getString("start_date"));
			int start_date_num = start_date.getYear()+1900;
			String year_str ;
			
		
			if(temp_month<6)
			{
				
				year_str =(temp_year-start_date_num) + "";
				
			}else{
			
				year_str =(temp_year-start_date_num+1)+"";
			}
			
			
			
			stu.setYear(year_str);
			stu.setSchool(rs.getString("school"));
			stu.setGpa(rs.getString("gpa"));
			stu.setStatus(rs.getString("status_name"));
			stu.setDepartment(rs.getString("department_name_th"));
			stu.setEntrance(rs.getString("entrance_name"));
			
		    entrance_id = rs.getInt("entrance_id");
			curr_id = rs.getString("curriculum_id");
			lecturer_id = rs.getString("lecturer_id");
			status_id = rs.getInt("status_id");
			degree = new String(rs.getString("degree"));		
			
			System.out.println("get lecturer name");
			ResultSet rs_lec = 
					connect.createStatement().executeQuery(" SELECT F.name_th , F.surname_th "+
														   " FROM full_name F , people P " +
														   " WHERE F.index=P.index " +
														   " AND F.full_name_id=P.full_name_id "+
														   " AND P.index='"+lecturer_id+"'");
			if(rs_lec.next())
			{
				stu.setLecturerName(rs_lec.getString("name_th"));
				stu.setLectuerSurname(rs_lec.getString("surname_th"));
			}
			
		}	
		
	
	
		
	}catch(Exception a){
		out.println(a.getMessage());
		a.printStackTrace();
		
	};
	

	connect.close();

%>

<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right"><label><font size="4" color="#ffffff">username : <%=strUser%>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>
				</tr>
			</table>
				
				<div id="main-content-ac">
				
					<br><br><br><br>
						
					<center>
					
					
					<input type="hidden" id="department" name="department" value="<%=department_id%>">
					<input type="hidden" id="curriculum" name="curriculum" value="<%=curriculum_id%>">
					<input type="hidden" id="full_name_id" name="full_name_id" value="<%=full_name_id%>">
					<input type="hidden" id="index" name="index" value="<%=index%>">
					
					
					<table width="1200px" border="0">
						
				        	<tr style="font-size:24px">
				        		<td  width="50" height="50" rowspan="5" style="text-align: center;">
				        		
						        			<img id="student_image" src="<%=stu.getPicture() %>" style="width:130px;height:160px;	">
						       
						          <form>	
										<input type="file" name="file"/><br />
										<div id="upload" style="display: none;">Uploading..</div>
										<div id="message">
										</div>
								  </form>
						      
						        </td>
						        
				<!-- 		   <form method="post" id="form" name="form" action"">	 -->     
						        <input type="hidden" name="personalId_old" value="<%=stu.getPersonalId()%>">
				                <td width="400" height="50">
				                	<font size="5"><strong>เลขประจำตัวประชาชน</strong></font>
				                </td>
				                <td width="600" height="50">
				                	<input type="text" id="personalId" name="personalId" style="font-size:18px" value="<%=stu.getPersonalId()%>" maxlength="13"/>
				                </td>
				                	               
				            </tr>
		
							<tr style="font-size:24px">
							<input type="hidden" name="title_old" value="<%=stu.getTitleEN()%>">
				                <td height="50">
				                	<font size="5"><strong>คำนำหน้า</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				   <%
				   				if("Mr.".equals(stu.getTitleEN()) || "นาย".equals(title_th)) {
				   					System.out.println("MR");////////////////////////////try////////////////////////
				   %>             	
				                      <label>
				                        <input type="radio" name="title" id="title" value="นาย" id="mr" checked="checked" onclick="click_title()" />
				                        <font size="5">นาย</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
				                        <font size="5">นาง</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
				                        <font size="5">นางสาว</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
				                        <font size="5">อื่นๆ</font>
				                       
				                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
				                      </label>
					<%
				   				}
				   				else if("Mrs.".equals(stu.getTitleEN()) || "นาง".equals(title_th)) {
				   					System.out.println("MRS");////////////////////////////try////////////////////////
					%>
								 	  <label>
				                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
				                        <font size="5">นาย</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นาง" id="mrs" checked="checked" onclick="click_title()" />
				                        <font size="5">นาง</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
				                        <font size="5">นางสาว</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
				                        <font size="5">อื่นๆ</font>
				                        
				                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
				                      </label>
				    <%
				   				}
				   				else if("Miss".equals(stu.getTitleEN()) || "นางสาว".equals(title_th)) {
				   					System.out.println("MISS");////////////////////////////try////////////////////////
				    %>
								 	  <label>
				                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
				                        <font size="5">นาย</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
				                        <font size="5">นาง</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" checked="checked" onclick="click_title()" />
				                        <font size="5">นางสาว</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
				                        <font size="5">อื่นๆ</font>
				                       
				                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
				                      </label>
				    <%
				   				}
				   				else {
				   					System.out.println("NO");////////////////////////////try////////////////////////
				    %>	
								 	  <label>
				                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
				                        <font size="5">นาย</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
				                        <font size="5">นาง</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()"  />
				                        <font size="5">นางสาว</font>
				                      </label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="title" id="title" value="etc" id="etc" checked="checked" onclick="click_title_etc()" />
				                        <font size="5">อื่นๆ</font>
				                        
				                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" value="<%=stu.getTitle() %>" />
				                      </label>
				    <%
				   				}
				    %>	                      
				                </td>
				            </tr>
				                 
				            <tr style="font-size:24px">
				            <input type="hidden" name="name_old" value="<%=stu.getNameTH()%>">
				                <td height="50">
				                	<font size="5"><strong>ชื่อ</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="name" id="name" type="text" style="font-size:18px" value="<%=stu.getNameTH() %>"/>
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="surname_old" value="<%=stu.getSurnameTH()%>">
				                <td height="50">
				                	<font size="5"><strong>นามสกุล</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="surname" id="surname" type="text" style="font-size:18px" value="<%=stu.getSurnameTH() %>" />
				                </td>
				                
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="name_en_old" value="<%=stu.getNameEN()%>">
				                <td height="50">
				                	<font size="5"><strong>ชื่อ(ภาษาอังกฤษ)</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="name_en" id="name_en" type="text" style="font-size:18px" value="<%=stu.getNameEN() %>" />
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="surname_en_old" value="<%=stu.getSurnameEN()%>">				            
				             	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>นามสกุล(ภาษาอังกฤษ)</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="surname_en" id="surname_en" type="text" style="font-size:18px" value="<%=stu.getSurnameEN() %>" />
				                </td>
				            </tr>
				            
							<tr style="font-size:24px">
				            <input type="hidden" name="gender_old" value="<%=stu.getGender()%>">	
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>เพศ</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				   
				    <%
				    				if("M".equals(stu.getGender())) {
				    %>
				   					 <label>
				                        <input type="radio" name="gender" value="M" id="man" checked="checked" />
				                        <font size="5">ชาย</font></label>
				                        
				                        &nbsp;&nbsp;
				                      
				                      <label>
				                        <input type="radio" name="gender" value="F" id="women" />
				                        <font size="5">หญิง</font></label>
				    <%
				    				}
				    				else {
				    %>
				    					<input type="radio" name="gender" value="M" id="man" />
				                        <font size="5">ชาย</font></label>
				    		                        
				                        &nbsp;&nbsp;
				                      
				                      <label>
				                        <input type="radio" name="gender" value="F" id="women" checked="checked" />
				                        <font size="5">หญิง</font></label>
				    <%					
				    				}
				    %>
				                      
				                </td>
				            </tr>
				            
				             <tr style="font-size:24px">
				             <input type="hidden" name="marital_status_old" value="<%=stu.getMaritalStatus()%>">	
				             	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>สถานภาพ</strong></font>
				                </td>
				                <td height="50">
				   <%
				   			if("โสด".equals(stu.getMaritalStatus())) {
				   %>
				                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="โสด" checked="checked" />
				                        <font size="5">โสด</font></label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
				                        <font size="5">แต่งงาน</font></label>
				                          &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
				                        <font size="5">หย่าร้าง</font></label>
				   <%
				   			}
				   			else if("แต่งงาน".equals(stu.getMaritalStatus())) {
				   %>               
				                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
				                        <font size="5">โสด</font></label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" checked="checked" />
				                        <font size="5">แต่งงาน</font></label>
				                          &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
				                        <font size="5">หย่าร้าง</font></label>		
				   <%
				   			}
				   			else if("หย่าร้าง".equals(stu.getMaritalStatus())) {
				   %>                    
				   		                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
				                        <font size="5">โสด</font></label>
				                      &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
				                        <font size="5">แต่งงาน</font></label>
				                          &nbsp;&nbsp;
				                      <label>
				                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" checked="checked" />
				                        <font size="5">หย่าร้าง</font></label>		
				   <%
				   			}
				   %>                    
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="date_of_birth_old" value="<%=stu.getBirtgdate()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
				
				                	<font size="5"><strong>วันเกิด (ว/ด/ป)</strong></font>
				                </td>
		
				                 <td height="50">
				                   <input type="date" id="date_of_birth" name="date_of_birth" value="<%=stu.getBirtgdate() %>"/>
		
				                </td>
				            </tr>
				                
				            <tr style="font-size:24px">
				            <input type="hidden" name="address_old" value="<%=stu.getAddress()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
									<font size="5"><strong>ที่อยู่</strong></font>
				                </td>
				                <td height="50">
				                	<textarea name="address" id="address" cols="50" rows="3"> <%=stu.getAddress() %> </textarea>
				                	
				                </td>
				           </tr>
				                
							<tr style="font-size:24px">
				            <input type="hidden" name="phonenumber_old" value="<%=stu.getTelephone()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>เบอร์โทรศัพท์</strong></font>
				                </td>
				                <td height="50">
				                	<input name="phonenumber" id="phonenumber" type="text" style="font-size:18px" value="<%=stu.getTelephone() %>" />
				                </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="email_old" value="<%=stu.getEmail()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
									<font size="5"><strong>E-mail</strong></font>
				                </td>
				                <td height="50">
				                	<input name="email" id="email" type="text" style="font-size:18px" value="<%=stu.getEmail() %>" />
				                </td>
				             </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="facebook_old" value="<%=stu.getFacebook()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
									<font size="5"><strong>Facebook</strong></font>
				                </td>
				                <td height="50">
				                	<input name="facebook" id="facebook" type="text" style="font-size:18px" value="<%=stu.getFacebook() %>" />
				                </td>
				            </tr>
				        
				            <tr style="font-size:24px">
				        	<input type="hidden" name="fatherName_old" value="<%=stu.getFatherName()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50"><font size="5"><strong>ชื่อบิดา</strong></font>
				                </td>
				                <td height="50">
				                	<input name="fatherName" id ="fatherName" type="text" style="font-size:18px" value="<%=stu.getFatherName() %>" />
				                </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="fatherAddress_old" value="<%=stu.getFatherAddress()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>ที่อยู่บิดา</strong></font>
				                </td>
				                <td height="50">
				                	<textarea name="fatherAddress" id="fatherAddress" cols="50" rows="3"><%=stu.getFatherAddress() %></textarea>
				              </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="fatherPhone_old" value="<%=stu.getFatherTelephone()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>เบอร์โทรศัพท์บิดา</strong></font>
				                </td>
				                <td height="50">
				                	<input name="fatherPhone" id="fatherPhone" type="text" style="font-size:18px" value="<%=stu.getFatherTelephone() %>" />
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="motherName_old" value="<%=stu.getMotherName()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50"><font size="5"><strong>ชื่อมารดา</strong></font>
				                </td>
				                <td height="50">
				                	<input name="motherName" id="motherName" type="text" style="font-size:18px" value="<%=stu.getMotherName() %>" />
				                </td>
				            </tr>
							
							<tr style="font-size:24px">
							<input type="hidden" name="motherAddress_old" value="<%=stu.getMotherAddress()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>ที่อยู่มารดา</strong></font>
				                </td>
				                <td height="50">
				                	<textarea name="motherAddress" id="motherAddress" cols="50" rows="3"><%=stu.getMotherAddress() %></textarea>
				                    
				              </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="motherPhone_old" value="<%=stu.getMotherTelephone()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>เบอร์โทรศัพท์มารดา</strong></font>
				                </td>
				                <td height="50">
				                	<input name="motherPhone" id="motherPhone" type="text" style="font-size:18px" value="<%=stu.getMotherTelephone() %>" />
				                </td>
				            </tr>
				              
				            <tr style="font-size:24px">
				            <input type="hidden" name="parentName_old" value="<%=stu.getParentName()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50"><font size="5"><strong>ชื่อผู้ปกครอง</strong></font>
				                </td>
				                <td height="50">	
				   <%
				   			if(father.equals(parent)) {
				   				System.out.println("SAME FATHER");////////////////////////////try////////////////////////
				   %>             
				                    <input name="parent_name"id="parent_name" type="radio"  value="sameFather" onclick="parent_is_father()" checked="checked" />
				                    <font size="5">บิดา</font>
				                    &nbsp;&nbsp;
				                    <input name="parent_name" id="parent_name" type="radio" value="sameMother" onclick="parent_is_mother()"/>
				                    <font size="5">มารดา</font>
				                    &nbsp;&nbsp;
				                    <input name="parent_name" id="parent_name" type="radio" value="etc" onclick="parent_etc()" />
				                    <font size="5">อื่นๆ</font>
				                    <input name="parentName" id="parentName" type="text" style="font-size:18px" readonly="readonly" />
				   <%
				   			}
				   			else if(mother.equals(parent)) {
				   				System.out.println("SAME MOTHER");////////////////////////////try////////////////////////
				   %>             
			                    <input name="parent_name"id="parent_name" type="radio"  value="sameFather" onclick="parent_is_father()" />
			                    <font size="5">บิดา</font>
			                    &nbsp;&nbsp;
			                    <input name="parent_name" id="parent_name" type="radio" value="sameMother" onclick="parent_is_mother()" checked="checked" />
			                    <font size="5">มารดา</font>
			                    &nbsp;&nbsp;
			                    <input name="parent_name" id="parent_name" type="radio" value="etc" onclick="parent_etc()" />
			                    <font size="5">อื่นๆ</font>
			                    <input name="parentName" id="parentName" type="text" style="font-size:18px" readonly="readonly" />
			   	   <%		   				
				   			}
				   			else {
				   				System.out.println("NOT SAME");////////////////////////////try////////////////////////
				   %>         
				   	            <input name="parent_name"id="parent_name" type="radio"  value="sameFather" onclick="parent_is_father()" />
			                    <font size="5">บิดา</font>
			                    &nbsp;&nbsp;
			                    <input name="parent_name" id="parent_name" type="radio" value="sameMother" onclick="parent_is_mother()" />
			                    <font size="5">มารดา</font>
			                    &nbsp;&nbsp;
			                    <input name="parent_name" id="parent_name" type="radio" value="etc" onclick="parent_etc()" checked="checked" />
			                    <font size="5">อื่นๆ</font>
			                    <input name="parentName" id="parentName" type="text" style="font-size:18px" value="<%=stu.getParentName() %>" />
			   	   <%		   				
				   			}
				   %>
				                </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="parentAddress_old" value="<%=stu.getParentAddress()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>ที่อยู่ผู้ปกครอง</strong></font>
				                </td>
				                <td height="50">
				   <%
				   			if(father.equals(parent) || mother.equals(parent)) {
				   %>             
				                	<textarea name="parentAddress" id="parentAddress" cols="50" rows="3" readonly="readonly"> <%=stu.getParentAddress() %> </textarea>
				   <%
				   			}
				   			else {
				   %>
				   					<textarea name="parentAddress" id="parentAddress" cols="50" rows="3" > <%=stu.getParentAddress() %> </textarea>
				   <%
				   			}
				   %>         
				              </td>
				            </tr>
				
							<input type="hidden" name="parentPhone_old" value="<%=stu.getParentTelephone()%>">
							<tr style="font-size:24px">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>เบอร์โทรศัพท์ผู้ปกครอง</strong></font>
				                </td>
				                <td height="50">
				   <%
				   			if(father.equals(parent) || mother.equals(parent)) {
				   %>             
				                	<input name="parentPhone" id="parentPhone" type="text" style="font-size:18px" value="<%=stu.getParentTelephone()%>" readonly="readonly" />
				   <%
				   			}
				   			else {
				   %>
				   					<input name="parentPhone" id="parentPhone" type="text" style="font-size:18px" value="<%=stu.getParentTelephone()%>" />
				   <%
				   			}
				   %>     
			
				                	
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="student_id" value="<%=stu.getStudentId()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>รหัสนักศึกษา</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="studentId" id="studentId" type="text" style="font-size:18px" value="<%=stu.getStudentId() %>" />
				                </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="entrance_old" value="<%=stu.getEntrance()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>Entrance</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<select name="entrance" id="entrance" style="font-size:18px">
				                        <option value="<%=entrance_id %>"><%=stu.getEntrance() %></option>
				                        
				                        
			                        	<%
			                         		int num_ent = entrance.size();
			                       
			                         		for(int i =0;i<num_ent;i++)
			                         		{
			                         			if(entrance_id == entrance.get(i).getEntranceId()) {}
			                         			else {
			                         			%>
			                         			 <option value="<%= entrance.get(i).getEntranceId()%>"><%= entrance.get(i).getEntranceName() %></option>
			                         			 
			                         			<% 
			                         			}
			                         		}
			                         	%>
				                   
				                   
				                   
				                   
				                   
				                    </select>
				                </td>
				            </tr>
				
							<tr style="font-size:24px">
							<input type="hidden" name="degree_old" value="<%=degree%>">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>ระดับการศึกษา</strong></font> 
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<select name="degree" id="degree" style="font-size:18px">
				    <%
				    				if("ปริญญาตรี".equals(degree)) {
				    %>
				                        <option value="bachelor">ปริญญาตรี</option>
				                        <option value="master">ปริญญาโท</option>
		
				    <%
				    				}
				    				else if("ปริญญาโท".equals(degree)) {
				    %>                
				                        <option value="master">ปริญญาโท</option>
				    		            <option value="bachelor">ปริญญาตรี</option>
				    <%
				    				}
				    %>                
				    				</select>
				                </td>
				            </tr>
				              
				            <tr style="font-size:24px">
				            <input type="hidden" name="school_old" value="<%=stu.getSchool()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>โรงเรียนเดิม</strong></font>
				                </td>
				                <td height="50">
				                	<input name="school" id="school" type="text" style="font-size:18px"  value="<%=stu.getSchool() %>"/>
				        		
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="gpa_old" value="<%=stu.getGpa()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>GPA (ม.ปลาย)</strong></font>
				                </td>
				                <td height="50">
				                	<input name="gpa" id="gpa" type="text" style="font-size:18px" value="<%=stu.getGpa()%>" />
				        			
				                </td>
				            </tr>
				            
				            
				            <tr style="font-size:24px">
				            	<td  width="400" height="50"></td>
				                <td height="50">
			
				                	<font size="5"><strong>วันที่เข้าศึกษา</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                   <input type="date" id="start_date" name="start_date" value="<%=start_date_old %>"/>
				                
				                </td>
				            </tr>
		
		
		
							<tr style="font-size:24px">
				            <input type="hidden" name="status_old" value="<%=stu.getStatus()%>">
								<td  width="400" height="50"></td>
				                <td height="50">
									<font size="5"><strong>สถานะ</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<select name="status" id="status" style="font-size:18px">
				                        <option value="<%=status_id %>"> <%=stu.getStatus() %> </option>
				      
				      					     <%
				                         		int num_sta = status.size();
				                       
				                         		for(int i =0;i<num_sta;i++)
				                         		{
				                         			if(status_id ==  status.get(i).getStatusId()) {}
				                         			else {
				                         			%>
				                         			 <option value="<%= status.get(i).getStatusId()%>"><%= status.get(i).getStatusName() %></option>
				                         			
				                         			<% 
				                         			}
				                         		}
				                         	%>				                        
				        			</select>
				                </td>
				            </tr>
				            
				            <tr style="font-size:24px">
				            <input type="hidden" name="lecturer_name_old" value="<%=stu.getLecturerName()+" "+stu.getLecturerSurname()%>">
				            	<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="5"><strong>อาจารย์ที่ปรึกษา</strong></font>
				         			<label><font size="5" color="#FF0000">*</font></label>
				                </td>
				                <td height="50">
				                	<input name="lecturer_name" id="lecturer_name" type="text" style="font-size:18px" value="<%=stu.getLecturerName()+" "+stu.getLecturerSurname() %>" list="namelist" onkeyup="search_name(this.value)"  />  <!-- <br><br> นามสกุล <input name="lecturer_surname" id="lecturer_surname" type="text" value="<%=stu.getLecturerSurname() %>" style="font-size:18px" />   -->
				                	<datalist id="namelist">
									</datalist>
				                </td>
				            </tr>
				
							
							<tr style="font-size:24px">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<font size="3" color="#FF0000">หมายเหตุ: * คือ ข้อมูลสำคัญ จำเป็นต้องกรอก</font>
				             	</td>
				             	<td></td>
				            </tr>
				
							<tr style="font-size:24px">
								<td  width="400" height="50"></td>
				                <td height="50">
				                	<input type="button" name="save" id="save"  value="save" class="buttonStyle"/>
				                </td>
				   <!--    </form>  -->
				                
				                <td height="50">
				                	<a href="student_edit.jsp"><button class="buttonStyle">cancel</button></a>
				                </td>
				            </tr>
						
					</table>
					
					</center>
									
					<br><br><br><br>
				
			<div style="clear: both;"></div>
				
			<div id="footer"></div>
			
		</div>		
			<div style="clear: both;"></div>		
   </div>


</body>
</html>